package com.xyh.transaction.alipay;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import com.alipay.easysdk.kernel.util.ResponseChecker;
import com.alipay.easysdk.payment.common.models.AlipayTradeFastpayRefundQueryResponse;
import com.alipay.easysdk.payment.facetoface.models.AlipayTradePrecreateResponse;
import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse;

import java.util.List;

public class Test {

    public static void main(String[] args) throws Exception {
        // 1. 设置参数（全局只需设置一次）
        Factory.setOptions(getOptions());
        // 构造请求参数以调用接口
        AlipayTradeFastpayRefundQueryResponse request = new AlipayTradeFastpayRefundQueryResponse();
        // sdk版本是"4.38.0.ALL"及以上,可以参考下面的示例获取诊断链接
        // String diagnosisUrl = DiagnosisUtils.getDiagnosisUrl(response);
        // System.out.println(diagnosisUrl);
    }

    //        try {
//            // 2. 发起API调用（以创建当面付收款二维码为例）
//            AlipayTradePrecreateResponse response = Factory.Payment.FaceToFace()
//                    .preCreate("Apple iPhone11 128G", "2234567890", "5799.00");
//
//            AlipayTradePagePayResponse re = Factory.Payment.Page().pay("Apple iPhone11 128G", "2234567890", "5799.00", "");
//            System.out.println(re.getBody());
//            // 3. 处理响应或异常
//            if (ResponseChecker.success(response)) {
//                System.out.println("调用成功");
//            } else {
//                System.err.println("调用失败，原因：" + response.msg + "，" + response.subMsg);
//            }
//        } catch (Exception e) {
//            System.err.println("调用遭遇异常，原因：" + e.getMessage());
//            throw new RuntimeException(e.getMessage(), e);
//        }
//    }
    private static Config getOptions() {
        Config config = new Config();
        config.protocol = "https";
        config.gatewayHost = "openapi-sandbox.dl.alipaydev.com";
        config.signType = "RSA2";
        config.appId = "9021000122684697";
        // 为避免私钥随源码泄露，推荐从文件中读取私钥字符串而不是写入源码中
        config.merchantPrivateKey = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCHpyPXTT7yf5zDOoXS6+khQQOtq+a8i00eQHs3fUZ996AGJd4ViqFL575n6uh4EDh1OJT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Kt+nQJeJrJAauSWVbQgz8yuBpiqofyEVxn3Nhr+TRAnakSZEt8ZsGcX43VaaDgYI4mSMuP2wPnJttXHJAoGBAJ2wTI18ifxxEGAfmP52JXyfMB2PXphpGR4TJ3Vd30O6DAbEYYZTNbNM23KXkwu8E8pGKNMOSsbIY7PHqrf8JQuAV0DmZ7mRCTum6AyoKrADD5fKqywJbCjyCJ6iKt7FxCmjHV/AamERm3e0QmMcxxZMzswQ6rmElWVkINupDAJ9AoGBAI+tbBYq6tUyu39hbB6bgqcUzoS05hLzOBhAZ6rQcjtcPDe0qzu2zKpH0Z4H5PLbSweWwKbxZJeyFWSMznl5FA+9ZVGP6SI+L7/HpZOrr1cHUB1z/cMeZ/sBLq/99pCJreLqdoKH+BV+rHobsQkm7mIJG4vPVMz1d3gZ66RX75v5";
        //注：证书文件路径支持设置为文件系统中的路径或CLASS_PATH中的路径，优先从文件系统中加载，加载失败后会继续尝试从CLASS_PATH中加载
//        config.merchantCertPath = "<-- 请填写您的应用公钥证书文件路径，例如：/foo/appCertPublicKey_2019051064521003.crt -->";
//        config.alipayCertPath = "<-- 请填写您的支付宝公钥证书文件路径，例如：/foo/alipayCertPublicKey_RSA2.crt -->";
//        config.alipayRootCertPath = "<-- 请填写您的支付宝根证书文件路径，例如：/foo/alipayRootCert.crt -->";
        //注：如果采用非证书模式，则无需赋值上面的三个证书路径，改为赋值如下的支付宝公钥字符串即可
         config.alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlttp+rxZA4p9EnZs4yANcNGK7GWr+EUsR7w7yhe+biipKt96KS7q3iN06UICBBU0aJ660mmYgabjCAJSmNMLujC3GWiaaiCtAxkxB3kGwEnNRGiDrWMBC7OGuRu0gmVB35GF3ur89bkS7wipIpN8Fm/KMPPAdHhK8s2O1vrMYwp0QW2fNV6H6G7KKIBhnSjyE0tLWwiAKPeQJuvjDRS7FCgJ7jRXtxKaJQD38O7oeotzoBpxwv3F1tJCIio6uLJyfLvgksW3IqQZjiWvsws1RW8lCJfjF8MlPtDabdkER4DOOk1cXqJFMNEUM/fL8yW1P7meRoCR/0jc6crjpz4rgQIDAQAB";
        //可设置异步通知接收服务地址（可选）
//        config.notifyUrl = "https://www.test.com/callback";
        //可设置AES密钥，调用AES加解密相关接口时需要（可选）
//        config.encryptKey = "<-- 请填写您的AES密钥，例如：aa4BtZ4tspm2wnXLb1ThQA== -->";
        return config;
    }

}
